<template>
    <div>
    <h1>会员添加</h1>
    </div>
    <table class="table table-border">
        <tbody>
            <tr>
                <td align="right">用户名字</td>
                <td>
                    <td><input type="text" v-model="info.userName"></td>
                </td>
            
                <td align="right">··手机号</td>
                <td><input type="text" v-model="info.userPhone" maxlength="11"></td>
            </tr>
            <tr>
                <td align="right">用户性别</td>
                <td >
                    <input type="radio" name="userSex" value=1 v-model="info.userSex" >男
                    <input type="radio" name="userSex" value=0 v-model="info.userSex" checked>女
                </td>
            
                <td align="right">会员等级</td>
                <td>
                    <select v-model="info.userLevel">
                        <option value="">请选择</option>
                        <option value="青铜会员">青铜会员</option>
                        <option value="黄金会员">黄金会员</option>
                        <option value="钻石会员">钻石会员</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td align="right">消费金额</td>
                <td><input type="text" v-model="info.userBuyqian"></td>
            
                <td align="right">消费次数</td>
                <td><input type="text"v-model="info.userPayNumber"></td>
            </tr>
            <tr>
                <td align="right">可用积分</td>
                <td><input type="text"v-model="info.userPotins"></td>
           
                <td align="right">可用余额</td>
                <td><input type="text"v-model="info.userMoney"></td>
            </tr>
            <tr>
                <td align="right">用户状态</td>
                 
                    <td >
                    <input type="checkbox" name="userSex" :value="1" >启/禁用
                     
                    </td>
                <td align="right">原因</td>
                <td>
                    <textarea>

                    </textarea>
                </td>
            </tr>
            <tr>
                <td></td>
                <td><input type='reset' value="取消"></td>
                <td></td>
                <td><input type='button' value="添加" @click="add"></td>
            </tr>
        </tbody>
    </table>
</template>

<script setup lang="ts">
import {ref,reactive} from'vue'
import axios from 'axios'

let info:any =reactive({
   
  "userName": "",
  "userSex": '',
  "userPhone": "",
  "userLevel": "",
  "userBuyqian": '',
  "userPayNumber": '',
  "userPotins": '',
  "userMoney":'',
  
})
//触发事件
const add=()=>
{
    if(info.userName=="")
{
    alert("用户名字不能为空");
    return;
}
// if(info.userSex=="")
// {
//     alert("用户性别不能为空");
//     return;
// }
//非空验证
if(info.userPhone=="")
{
    alert("用户手机号不能为空");
    return;
}
if(info.userLevel=="")
{
    alert("用户会员等级不能为空");
    return;
}
if(info.userBuyqian=="")
{
    alert("用户消费金额不能为空");
    return;
}
if(info.userPayNumber=="")
{
    alert("用户消费次数不能为空");
    return;
}
if(info.userMoney=="")
{
    alert("用户余额不能为空");
    return;
}
if(info.userPotins=="")
{
    alert("用户积分不能为空");
    return;
}
if(info.userPotins<0||info.userPotins>1000)
{
    alert("用户积分不能超过1000分和小于0分")
    return;
}
//发送网络请求
axios({
    url:'https://localhost:7155/api/User/ADD',
    method:'post',
    data:info,
})
.then(rec=>{
    console.log(rec);
    if(rec.data>0)
{
    alert("添加成功");
    return;
}
else if(rec.data==-1)
{
    alert("用户不能重复");
    return;
}
else
{
    alert("添加失败")
}
})
.catch(err=>{
    console.log(err);
})
}



</script>










<style scoped>

</style>